<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Map Fang</title>
<link href="{? $global.url.css ?}reset.css" rel="stylesheet" type="text/css">
<script	src="{? $global.url.jquery ?}jquery-latest.js"></script>
<script
	src="http://ditu.google.cn/maps?file=api&amp;v=2.x&amp;key={? $global.map.key ?}&hl=zh-CN&sensor=true"
	type="text/javascript"></script>
<script type="text/javascript">    
	var map = null;
	var geocoder = null;
	var marker = null;
	
	function initialize() {
	  if (GBrowserIsCompatible()) {
	    map = new GMap2(document.getElementById("map_canvas"));
	    map.setCenter(new GLatLng(39.917, 116.397), 13);
		GEvent.addListener(map, "click", getAddress);
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setUIToDefault();
		
        // bind a search control to the map, suppress result list
        //map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
	    geocoder = new GClientGeocoder();
	  }
	}
	
	function showAddress(address) {
	  if (geocoder) {
	    geocoder.getLatLng(
	      address,
	      function(point) {
	        if (!point) {
	          alert("不能解析: " + address);
	        } else {
	          map.setCenter(point, 13);
	          var marker = new GMarker(point);
	          map.addOverlay(marker);
	          marker.openInfoWindowHtml(address);
	        }
	      }
	    );
	  }
	}

	function getAddress(overlay, latlng) {
	  if (latlng != null) {
	    var address = latlng;
	    geocoder.getLocations(latlng, findAddress);
	    //point = new GLatLng(latlng.lat(), latlng.lng());
	    marker = new GMarker(latlng);
	    map.addOverlay(marker);
	  }
	}
	
	function findAddress(response) {
	  //map.clearOverlays();
	  if (!response || response.Status.code != 200) {
	    alert("Status Code:" + response.Status.code);
	  } else {
	   place = response.Placemark[0];
	    //point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
	   // marker = new GMarker(point);
	   // map.addOverlay(marker);
	   marker.bindInfoWindowHtml(
	    	'<div style="font-size:12px; line-height:1.4;">'
	    	+ '<b>坐标:</b><input type=text value=' + response.name + ' /><br/>'
	        //'<b>现坐标:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
	        + '<b>地址:</b><input type=text value=' + place.address + ' /><br>');
	        //'<b>国家:</b>' + place.AddressDetails.Country.CountryNameCode);

       //maker.bindInfoWindowHtml('sdfsdfsdfsdfsd');
	  }
	}
</script>
<script type="text/javascript">
$().ready(function(){
	var pageheight = document.documentElement.clientHeight;
	var headheight = $('#header')[0].offsetHeight;
	var footheight = $('#footer')[0].clientHeight;
	var pagewidth = document.documentElement.clientWidth;
	//alert(pageheight-headheight);
	$('#map_canvas').css('height', pageheight-headheight-footheight-2);
	$('#map_canvas').css('width', pagewidth-2);
});
</script>
</head>

<body onload="initialize()" onunload="GUnload()">
<!--header start!-->
<div id="header">
<h2>header</h2>
<input type='text' id='address' /><input type='button' value='查找' onclick='showAddress($("#address").val());' />
</div>
<!--header end!-->